<script lang="ts" setup>
import { getWarningListAPI } from '@/apis/pole';
import type { Warning, WarningListParams } from '@/types/pole';
import { ref } from 'vue';


const list = ref<Warning[]>([])
const total = ref(0)
const params = ref<WarningListParams>({
  page: 1,
  pageSize: 10,
  handleStatus: '',
  poleName: '',
  poleNumber: '',
})
const getList = async () => {
  const res = await getWarningListAPI(params.value)
  console.log('list',res)
  list.value =res.data.rows
  total.value = res.data.total
}
getList()
const onSearch = () => {
  params.value.page = 1
  getList()
}
</script>

<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">一体杆名称：</span>
      <el-input clearable v-model="params.poleName" placeholder="请输入一体杆名称" class="search-main" />
      <span class="search-label">一体杆编号：</span>
      <el-input clearable v-model="params.poleNumber" placeholder="请输入一体杆编号" class="search-main" />
      <span class="search-label">处置状态：</span>
      <el-select style="width: 240px" v-model="params.handleStatus" placeholder="全部" clearable>
        <el-option label="未派单" value="0" />
        <el-option label="已派单" value="1" />
        <el-option label="已接单" value="2" />
        <el-option label="已完成" value="3" />
      </el-select>
      <el-button type="primary" class="search-btn" @click="onSearch">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table  style="width: 100%" :data="list">
        <el-table-column type="index" label="序号" width="100" />
        <el-table-column prop="poleName" label="一体杆名称" />
        <el-table-column prop="poleNumber" label="一体杆编号" />
        <el-table-column prop="errorType" label="故障类型" />
        <el-table-column prop="handleStatus" label="处置状态">
          <template #default="{ row }">
            <span v-if="row.handleStatus === 0">未派单</span>
            <span v-else-if="row.handleStatus === 1">已派单</span>
            <span v-else-if="row.handleStatus === 2">已接单</span>
            <span v-else-if="row.handleStatus === 3">已完成</span>
          </template>
        </el-table-column>
        <el-table-column prop="warningTime" label="告警时间" />
        <el-table-column label="操作" fixed="right">
          <template #default="{ row }">
            <el-button size="small" type="primary" link disabled>派单</el-button>
            <el-button size="small" type="primary" link @click="$router.push(`/warn/detail/${row.id}`)" >详情</el-button>
            <el-button size="small" type="primary" link disabled>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination 
      layout="total, prev, pager, next, sizes, jumper"
      :page-sizes="[2, 5, 10, 20, 100]"
      :total="total" 
      v-model:current-page="params.page" 
      v-model:page-size="params.pageSize"
      @change="getList()"
      />
    </div>
    
  </div>
</template>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.create-container {
  margin: 10px 0px;
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>